package com.example.service.userImpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.domain.user;
import com.example.mapper.user.userQuery;
import com.example.service.user.insertUserservice;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class insertUserserviceImpl extends ServiceImpl<userQuery, user> implements insertUserservice {

    @Resource
    private userQuery userQuery;


    @Override
    public boolean insert(user users) {
        return userQuery.insert(users)>0;
    }

    @Override
    public user getByOpenId(String openId) {
        return userQuery.selectByOpenId(openId);
    }

    @Override
    public Boolean updata(user users) {
        return userQuery.updateById(users)>0;
    }

    @Override
    public List<user> selectall(int a, int b) {
        return userQuery.findAll(a,b);
    }

    @Override
    public int allnumber() {
        return userQuery.allnumber();
    }


    @Override
    public IPage<user> getPage(int currentPage, int pageSize, user user) {
        LambdaQueryWrapper<user> lqw = new LambdaQueryWrapper<user>();
        lqw.like(Strings.isNotEmpty(user.getName()), com.example.domain.user::getName,user.getName());
        lqw.like(Strings.isNotEmpty(user.getAdminname()), com.example.domain.user::getAdminname,user.getAdminname());
        IPage page = new Page(currentPage,pageSize);
        userQuery.selectPage(page,lqw);
        return page;
    }

    @Override
    public IPage<user> getPagebyname(int currentPage, int pageSize, user user) {
        LambdaQueryWrapper<user> lqw = new LambdaQueryWrapper<user>();
        lqw.like(Strings.isNotEmpty(user.getName()), com.example.domain.user::getName,user.getName());
        lqw.like(Strings.isNotEmpty(user.getAdminname()), com.example.domain.user::getAdminname,user.getAdminname());
        IPage page = new Page(currentPage,pageSize);
        userQuery.selectPage(page,lqw);
        return page;
    }
}
